#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
//#include <errno.h> 

int getfsuid(uid_t *fsuid) 
{ 
	pid_t pid; 
	char filename[1024], str[1024], *str2; 
	FILE *fp; 
	int i; 


	if ((pid = getpid()) < 0) 
	{ 
		perror("getpid()");
		exit(1);
	} 
	sprintf(filename, "/proc/%u/status", pid);
	if ((fp = fopen(filename, "r")) == NULL) 
	{ 
		perror("fopen()");
		exit(1); 
	} 
	while (fgets(str, 1023, fp) != NULL) 
	 { 
		if ((str2 = strstr(str, "Uid:")) == str)
		{ 
			strtok(str, "\t");
			for (i = 0; i < 4; i++)
			str2 = strtok(NULL, "\t");
			*fsuid = atoi(str2);
			fclose(fp);
			return 0;
		} 
	} 
return -1; 
}

int main(int argc, char** argv) 
{
	uid_t ruid, euid, suid, fsuid;

/* show the current uids */
	if( (getresuid(&ruid, &euid, &suid))<0 )
	{
		perror("getresuid() failed!");
		exit(1);
	}
	if( (getfsuid(&fsuid))<0 )
	{
		perror("getfsuid() failed!");
		exit(1);
	}	
	printf("CURRENT real-user-id=%d\t",ruid);
	printf("effective-user-id=%d\t",euid);
	printf("saved-set-user-id=%d\t",suid);
	printf("fs-user-id=%d\n",fsuid);
	
	return 0;
}
